﻿using CowsAndBulls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace TestCowsAndBulls
{
    [TestClass()]
    public class ScoreBoardTest
    {
        [TestMethod()]
        public void InsertPlayerInScoreBoardTestBasic()
        {
            int attempts = 5;
            string name = "Pe6o";
            ScoreBoard target = new ScoreBoard(attempts, name);
            List<ScoreBoard> list = new List<ScoreBoard>();
            target.InsertPlayerInScoreBoard(list);
            Assert.AreEqual(list.Count, 1);
            Assert.AreEqual(list[0], target);
        }

        [TestMethod()]
        public void InsertPlayerInScoreBoardTestSort()
        {
            int[] attempts = { 5, 10, 3, 6, 0 };
            string[] name = { "Pe6o", "Sa6o", "To6o", "Go6o", "Chuck Norris" };
            ScoreBoard[] targets = new ScoreBoard[attempts.Length];

            List<ScoreBoard> list = new List<ScoreBoard>();
            for (int i = 0; i < attempts.Length; i++)
            {
                ScoreBoard target = new ScoreBoard(attempts[i], name[i]);
                target.InsertPlayerInScoreBoard(list);
                targets[i] = target;
            }
            Assert.AreEqual(list.Count, 5);
            Assert.AreEqual(list[0], targets[4]);
            Assert.AreEqual(list[1], targets[2]);
            Assert.AreEqual(list[2], targets[0]);
            Assert.AreEqual(list[3], targets[3]);
            Assert.AreEqual(list[4], targets[1]);
        }

        [TestMethod()]
        public void InsertPlayerInScoreBoardTestSortAndRemove()
        {
            int[] attempts = { 5, 10, 3, 6, 0 };
            string[] name = { "Pe6o", "Sa6o", "To6o", "Go6o", "Chuck Norris"};
            ScoreBoard[] targets = new ScoreBoard[attempts.Length];

            List<ScoreBoard> list = new List<ScoreBoard>();
            for (int i = 0; i < attempts.Length; i++)
            {
                ScoreBoard target = new ScoreBoard(attempts[i], name[i]);
                target.InsertPlayerInScoreBoard(list);
                targets[i] = target;
            }
            Assert.AreEqual(list.Count, 5);
            Assert.AreEqual(list[0], targets[4]);
            Assert.AreEqual(list[1], targets[2]);
            Assert.AreEqual(list[2], targets[0]);
            Assert.AreEqual(list[3], targets[3]);
            Assert.AreEqual(list[4], targets[1]);
        }

        [TestMethod()]
        public void InsertPlayerInScoreBoardTestEqualScore()
        {
            int[] attempts = { 5, 10, 3, 6, 0, 0 };
            string[] name = { "Pe6o", "Sa6o", "To6o", "Go6o", "Chuck Norris", "Boiko Borisov" };
            ScoreBoard[] targets = new ScoreBoard[attempts.Length];

            List<ScoreBoard> list = new List<ScoreBoard>();
            for (int i = 0; i < attempts.Length; i++)
            {
                ScoreBoard target = new ScoreBoard(attempts[i], name[i]);
                target.InsertPlayerInScoreBoard(list);
                targets[i] = target;
            }
            Assert.AreEqual(list.Count, 5);
            Assert.AreEqual(list[0].CountAttempts, list[1].CountAttempts);
            Assert.IsTrue(list[0].PlayerName == name[4] && list[1].PlayerName == name[5] ||
                list[0].PlayerName == name[5] && list[1].PlayerName == name[4]);
        }
    }
}
